import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { ViewController } from 'ionic-angular/navigation/view-controller';
import { HttpHeaders } from '@angular/common/http';
import { News } from '../../providers/news-data/news';
import { NewsDataProvider } from '../../providers/news-data/news-data';


@Component({
  selector: 'page-input-task',
  templateUrl: 'input-task.html',
})
export class InputTaskPage {

  name:string;
  img:string;
  intro:string;
  time:string;
  address:string;
  objectId:string;

  action:string='新增';

  constructor(public navCtrl: NavController, 
    public navParams: NavParams,
    public viewCtrl:ViewController,
    public http:NewsDataProvider) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad InputTaskPage');
  }

  close(){
    this.viewCtrl.dismiss();
  }

  saveNews(){
    let _news: News={
      name:this.name,
      img:this.img,
      intro:this.intro,
      time:this.time,
      address:this.address,
      objectId:this.objectId
    };
    if (this.action === '新增') {
      this.http.addNews(_news).subscribe(data=>_news.objectId=data.objectId);
    }
    this.viewCtrl.dismiss(_news);

  }

  
}
